package day07;

import java.util.Random;
import java.util.Scanner;

public class Practice {
    public static void main(String[] args) {
        //String code=veriCode(6);
        //System.out.println("验证码为："+code);
        /*
        for(int num=2;num<100;num++) {
            boolean flag = true;
            for (int i = 2; i <= num / 2; i++) {
                if (num % i == 0) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                System.out.print(num + " ");
            }
        }

         */

        /*
        Scanner scan=new Scanner(System.in);
        Random rand=new Random();
        int num=rand.nextInt(1001);
        while (true){
            System.out.println("猜吧");
            int answer=scan.nextInt();
            if(answer>num){
                System.out.println("猜大了");
            }else if(answer<num){
                System.out.println("猜小了");
            }else{
                System.out.println("猜对了");
                break;
            }

        }

         */

        /*
        Scanner scan = new Scanner(System.in);
        System.out.println("请输入机票原价");
        double price = scan.nextDouble();
        System.out.println("请输入月份");
        int month = scan.nextInt();
        System.out.println("请输入舱位类型:1.头等舱 2.商务舱 3.经济舱");
        int num = scan.nextInt();
        double airPrice=airPrice(price,month,num);
        if(airPrice!=-1){
            System.out.println("最终票价为："+airPrice);
        }

         */
        double[] scores=scores(6);
        //double sum=calTotal(scores);
        //System.out.println("总分为："+sum);
        double avg=calAvg(scores);
        System.out.println("平均分为："+avg);


    }

    public static String veriCode(int len) {
        String code = "";
        char[] chs = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
                'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A',
                'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
                'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2',
                '3', '4', '5', '6', '7', '8', '9', '达', '内'};
        Random rand = new Random();
        for (int i = 1; i <= len; i++) {
            int index = rand.nextInt(chs.length);
            code += chs[index];
        }
        return code;
    }

    public static double airPrice(double price, int month, int type) {
        double finalPrice = 0.0;
        if (month <= 0 || month > 12) {
            System.out.println("月份输入错误");
            return -1;
        }
        if (type <= 0 || type > 3) {
            System.out.println("类型输入错误");
            return -1;
        }
        if (month <= 10 && month >= 5) {
            switch (type) {
                case 1:
                    finalPrice = price * 0.9;
                    break;
                case 2:
                    finalPrice = price * 0.85;
                    break;
                case 3:
                    finalPrice = price * 0.85;
                    break;
            }
        } else {
            switch (type) {
                case 1:
                    finalPrice = price * 0.8;
                    break;
                case 2:
                    finalPrice = price * 0.7;
                    break;
                case 3:
                    finalPrice = price * 0.6;
                    break;
            }
        }
        return finalPrice;
    }

    public static double[] scores(int num){
        double[] scores=new double[num];
        Scanner scan=new Scanner(System.in);
        for(int i=0;i<num;i++){
            System.out.println("请输入第"+(i+1)+"个评委的分数");
            double score=scan.nextDouble();
            scores[i]=score;
        }
        return scores;
    }

    public static double calTotal(double[] scores){
        double total=0.0;
        double max=scores[0];
        double min=scores[0];
        for(int i=0;i<scores.length;i++){
            if(scores[i]>max){
                max=scores[i];
            }
            if(scores[i]<min){
                min=scores[i];
            }
            total+=scores[i];
        }
        return total-max-min;
    }

    public static double calAvg(double[] scores){
        double avg=0.0;
        double sum=calTotal(scores);
        avg=sum/(scores.length-2);
        return avg;
    }

}
